﻿using MyTest;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Collection : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        #region 关联性泛型集合（Key-Value）

        #region Dictionary（哈希表）
        Dictionary<string, Product2> dictProducts = new Dictionary<string, Product2>();
        dictProducts.Add("t1",new Product2());
        dictProducts.Add("t2", new Product2());
        dictProducts.Add("t3", new Product2());
        Response.Write("字典集合大小"+dictProducts.Count+"<br>");
        Product2 p;
        Response.Write(dictProducts.TryGetValue("t1",out p)+"<br>");
        StringBuilder sb = new StringBuilder();
        //dictProducts.Values;//字典值的集合
        foreach (var key in dictProducts.Keys)
        {
            sb.Append(key+"\t");
        }
        Response.Write(sb.ToString()+"<br>");
        #endregion

        #region SortedDictionary（二叉树）
        SortedDictionary<string, Product2> sDictProducts = new SortedDictionary<string,Product2>();
        sDictProducts.Add("t1", new Product2());
        sDictProducts.Add("t2", new Product2());
        sDictProducts.Add("t3", new Product2());
        sDictProducts.Add("t4", new Product2());
        Response.Write("字典集合大小" + sDictProducts.Count + "<br>");
        Response.Write(sDictProducts.ContainsKey("t10")+"<br>");
        StringBuilder sb2 = new StringBuilder();
        foreach (var key in sDictProducts.Keys)
        {
            sb2.Append(key + "\t");
        }
        Response.Write(sb2.ToString()+"<br>");

        #endregion

        #endregion
    }
}